﻿

using Prism.Ioc;
using Prism.Unity;
using System;
using System.Threading;
using System.Windows;
using CCSFeederCameraUI2.Views;
using CCSFeederCameraUI2.Models;
using CCSFeederCameraUI2.Services;
using CCSFeederCameraUI2.Views.Dialogs;
using CCSFeederCameraUI2.ViewModels.Dialogs;
using CCSFeederCameraUI2.Data.Common.Services;
using CCSFeederCameraUI2.ViewModels.Dialogs.PartNum;
using CCSFeederCameraUI2.Views.Dialogs.PartNum;
using Prism.Modularity;

namespace CCSFeederCameraUI2
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
    {
        private static Mutex _mutex = null;
        protected override void OnStartup(StartupEventArgs e)
        {
            const string appName = "CCSFeederCameraUI2";
            bool createdNew;

            _mutex = new Mutex(true, appName, out createdNew);

            if (!createdNew)
            {
                MessageBox.Show("CCSFeederCameraUI2软件已开启", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                //app is already running! Exiting the application  
                Environment.Exit(-1);
            }

            base.OnStartup(e);
        }
        protected override Window CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }
        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterSingleton<DrawROI>();
            containerRegistry.Register<IDialogHostService, DialogHostService>();

            containerRegistry.RegisterSingleton<ICameraService, CameraService>("LeftCamera");
            containerRegistry.RegisterSingleton<ICameraService, CameraService>("RightCamera");
            containerRegistry.RegisterSingleton<IPLCService, PLCService>("PLC");
            containerRegistry.RegisterSingleton<IScanner, Scanner>("Scanner");

            containerRegistry.RegisterDialog<CameraVisionDialog, CameraVisionDialogViewModel>();
            containerRegistry.RegisterDialog<PartNumDialog, PartNumDialogViewModel>();
            containerRegistry.RegisterDialog<ParameterDialog, ParameterDialogViewModel>();

            containerRegistry.RegisterDialog<AddNewPartNumDialog, AddNewPartNumDialogViewModel>();
        }
        protected override IModuleCatalog CreateModuleCatalog()
        {
            return new ConfigurationModuleCatalog();
        }
    }
}
